import com.beust.jcommander.JCommander;
import compiler.Compiler;
import compiler.RunnerClassCompiler;

import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        CommandLineArgs jct = new CommandLineArgs();
        new JCommander(jct, args);

        if (jct.interpretFilePath != null) {
            Scanner scanner;
            StringBuilder program = new StringBuilder();
            scanner = new Scanner(new FileReader(jct.interpretFilePath));
            while (scanner.hasNextLine()) {
                program.append(scanner.nextLine());
                program.append(" ");
            }
            Interfaces.Runner mainRunner = new Compiler();
            System.out.print(mainRunner.run(program.toString()));
        } else if (jct.pathToCompile != null & jct.className != null) {
            Scanner scanner;
            StringBuilder program = new StringBuilder();
            program.append("let ");
            program.append(jct.className);
            program.append("= \\() -> ");
            scanner = new Scanner(new FileReader(jct.pathToCompile));
            while (scanner.hasNextLine()) {
                program.append(scanner.nextLine());
                program.append(" ");
            }
            program.append(" in " + jct.className);
            Compiler compiler = new Compiler();
            compiler.compile(program.toString());
            RunnerClassCompiler runnerCompiler = new RunnerClassCompiler(jct.className.toUpperCase(), jct.className.toUpperCase(), jct.className + "Runner");
            runnerCompiler.compile();

        } else {
            System.out.println("Command not found");
        }
    }
}
